<template>
  <div class="field-wrapper" @mouseover="enter" @mouseleave="leave">
    <el-form-item  :label="data.name" class="selected">
      <slot></slot>
    </el-form-item>

    <template v-if="true">
      <div class="field-action" v-if="true">
        <i title="选中父组件" @click.stop="selectParentWidget(field)">
           <SvgIcon icon-class="el-back" />
        </i>
        <i  title="上移组件"
           @click.stop="moveUpWidget(field)"><SvgIcon icon-class="el-move-up" /></i>
        <i  title="下移组件"
           @click.stop="moveDownWidget(field)"><SvgIcon icon-class="el-move-down" /></i>
        <i  title="复制组件"
         @click.stop="cloneContainer(widget)"><SvgIcon icon-class="el-clone" /></i>
        <i title="删除组件" @click.stop="removeFieldWidget">
          <SvgIcon icon-class="el-delete" />
        </i>
      </div>

      <div class="drag-handler background-opacity" v-if="true">
        <i title="拖拽手柄"><SvgIcon icon-class="el-drag-move" /></i>
        <i>{{data.name}}</i>
        <i><SvgIcon icon-class="el-hide" /></i>
      </div>
    </template>
  </div>
</template>

<script setup lang="ts">
  import { reactive, toRefs, watch} from 'vue'
  import SvgIcon from '@/designer/svgIcon'
  const parentData = defineProps({
      data:{
          type: String,
          name: String
       }
  });
</script>

<style lang="scss" scoped>
  $--color-primary: #409EFF;

  .design-time-bottom-margin {
    margin-bottom: 5px;
  }

  .field-wrapper {
    position: relative;

    .field-action{
      position: absolute;
      //bottom: -24px;
      bottom: 0;
      right: -2px;
      height: 22px;
      line-height: 22px;
      background: $--color-primary;
      z-index: 9;

      i {
        font-size: 14px;
        color: #fff;
        margin: 0 3px;
        cursor: pointer;
      }
    }

    .drag-handler {
      position: absolute;
      top: 0;
      //bottom: -22px;  /* 拖拽手柄位于组件下方，有时无法正常拖动，原因未明？？ */
      left: -1px;
      height: 20px;
      line-height: 20px;
      //background: $--color-primary;
      z-index: 9;

      i {
        font-size: 12px;
        font-style: normal;
        color: #fff;
        margin: 4px;
        cursor: move;
      }

      &:hover {
        //opacity: 1;
        background: $--color-primary;
      }
    }
  }

  .field-action, .drag-handler {
    :deep(.svg-icon) {
      margin-left: 0;
      margin-right: 0;
    }
  }

  .el-form-item {
    //margin-bottom: 0 !important;
    //margin-bottom: 6px;

    //margin-top: 2px;
    position: relative;

    :deep(.el-form-item__label) {
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    :deep(.el-form-item__content) {
      //position: unset;  /* TODO: 忘了这个样式设置是为了解决什么问题？？ */
    }

    span.custom-label i {
      margin: 0 3px;
    }

    /* 隐藏Chrome浏览器中el-input数字输入框右侧的上下调整小箭头 */
    :deep(.hide-spin-button) input::-webkit-outer-spin-button,
    :deep(.hide-spin-button) input::-webkit-inner-spin-button {
      -webkit-appearance: none !important;
    }

    /* 隐藏Firefox浏览器中el-input数字输入框右侧的上下调整小箭头 */
    :deep(.hide-spin-button) input[type="number"] {
      -moz-appearance: textfield;
    }
  }

  .required :deep(.el-form-item__label)::before {
    content: '*';
    color: #F56C6C;
    margin-right: 4px;
  }

  .static-content-item {
    min-height: 20px;
    display: flex;  /* 垂直居中 */
    align-items: center;  /* 垂直居中 */

    :deep(.el-divider--horizontal) {
      margin: 0;
    }
  }

  .el-form-item.selected, .static-content-item.selected {
    outline: 2px solid $--color-primary;
  }

  :deep(.label-left-align) .el-form-item__label {
    text-align: left;
    justify-content: flex-start !important;
  }

  :deep(.label-center-align) .el-form-item__label {
    text-align: center;
    justify-content: center !important;
  }

  :deep(.label-right-align) .el-form-item__label {
    text-align: right;
    justify-content: flex-end !important;
  }


</style>
